// ��
#include "main.h"
#include "Driver/inc/remote_sys.h"
#include "Driver/inc/speech_sys.h"
#include "debug.h"
int numx = 0;
int numy = 0;
int cir = 120;
rt_uint8_t flag_my = 0;

int main(void)
{
    // int start_time = clock();
    rt_thread_mdelay(510);
    // int end_time = clock();
    // rt_kprintf("\r\ntime:%d\r\n", end_time - start_time);

    int remote_mode = 0;
    static rt_uint8_t print_value[2];
    rt_uint8_t CurKey = 0;
    rt_kprintf("MCU: CH32V307\n");
    rt_kprintf("SysClk: %dMHz\n", SystemCoreClock / 1000000);
    rt_kprintf("wlingL\n");

    //    at_client_init("uartlcd_set_color7",512);

    // rt_key_init();
    key_init();
    led_init();
    remote_sys_init();
    wifi_init();
    // rt_pin_write(LED1_PIN, PIN_LOW);
    rt_pin_write(LED2_PIN, PIN_LOW);

    lcd_set_color(BLACK, RED);
    lcd_clear(BLACK);

    speech_sys();

    //    led_Toggle(LED2_PIN);

    //    rt_kprintf("main:inst0_do:%d\r\n", inst0_do);
    state_door = 1;
    state_lamp = 1;
    state_curtain = 1;

    rt_thread_mdelay(101);
    //    printf("tt1");

    while (1)
    {
        rt_thread_mdelay(200);
        if (remote_mode == 0)
        {
            remote_sys();
        }
        else if (remote_mode == 1)
        {
            wifi_ctrl();
        }
        //        printf("tewrst1");
        //        remote_sys();
        GUI();
        //        rt_thread_mdelay(2150);
        //           DHT11_REC_Data();
        //        printf("温度：%d'c\r\n", rec_data[2]);
        //        printf("湿度：%d%%\r\n", rec_data[0]);
        //        printf("\r\n\n");
        //        printf("test1");

        CurKey = key_scan();
        sprintf((char *)print_value, "CurKey:%d", CurKey);
        lcd_x = 0;
        lcd_y = 24 * 5;
        lcd_show_string(lcd_x, lcd_y, 24, (char *)print_value);
        if (CurKey == 1)
        {
            remote_mode = 0;
            // remote_sys_init();
        }
        else if (CurKey == 2)
        {
            remote_mode = 1;
            // wifi_init();
        }
        if (CurKey == 7)
        {
            remote_mode = 3;
            //                   wifi_init();
        }

        //        else if (CurKey == 3)
        //        {
        //            key_up();
        //            display_cursor();
        //        }
        //        else if (CurKey == 4)
        //        {
        //            key_down();
        //            display_cursor();
        //        }
    }
    led_Toggle(LED1_PIN);
    // int start_time = clock();
    rt_thread_mdelay(510);
    // int end_time = clock();
    // rt_kprintf("time:%d", end_time-start_time);
}

int my(int argc, char **argv)
{
    numx = atoi(argv[1]);
    numy = atoi(argv[2]);
    //    lcd_show_string(numx, numy, 24, "B");
    // rt_kprintf("%s,%s", argv[1], argv[2]);
    flag_my = 1;
    return 0;
}

int my_d(int argc, char **argv)
{
    int se = atoi(argv[1]);
    cir = atoi(argv[2]);
    //    lcd_show_string(numx, numy, 24, "B");
    // rt_kprintf("%s,%s", argv[1], argv[2]);
    rt_kprintf("%s", argv[0]);
    if (se == 1)
    {
        // 开窗
        open_curtain(1);
    }
    else if (se == 2)
    {
        // 关窗
        open_curtain(0);
    }
    else if (se == 3)
    {
        // 关门
        open_door(1);
    }
    else if (se == 4)
    {
        // 开门
        open_door(0);
    }
    return 0;
}
MSH_CMD_EXPORT(my, my fun for disp);
MSH_CMD_EXPORT(my_d, my fun for door);
